﻿using System;
using System.Text;
using System.Web.Services;
using OpenPhotoAlbum.BusinessLogics;

namespace OpenPhotoAlbum.My
{
	/// <summary>
	/// Summary description for Albums
	/// </summary>
	[WebService(Namespace = "http://tempuri.org/")]
	[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
	[System.ComponentModel.ToolboxItem(false)]
	// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line. 
	[System.Web.Script.Services.ScriptService]
	public class Albums : AlbumWebService
	{
		[WebMethod]
		public string UpdateAlbumTitle(Guid albumId, string albumTitle)
		{
			AssertAlbumOwner(albumId);

			AlbumManager.Instance.UpdateAlbumTitle(albumId, albumTitle);

			DateTime date = AlbumManager.Instance.GetLastModificationDate(albumId);
			string dateStr = Controls.StringUtility.Format(
				Resources.Strings.My_Album_LastModificationDate,
				date.ToShortDateString());

			StringBuilder result = new StringBuilder();
			result.Append(UrlContext.BuildMyAlbumUrl(0, albumId, albumTitle, 0));
			result.Append('|');
			result.Append(dateStr);

			return result.ToString();
		}

		[WebMethod]
		public string UpdateAlbumDescription(Guid albumId, string albumDescription)
		{
			AssertAlbumOwner(albumId);

			BusinessLogics.AlbumManager.Instance.UpdateAlbumDescription(albumId, albumDescription);

			DateTime date = AlbumManager.Instance.GetLastModificationDate(albumId);
			string result = Controls.StringUtility.Format(
				Resources.Strings.My_Album_LastModificationDate,
				date.ToShortDateString());
				
			return result;
		}

		//[WebMethod]
		//public string GetLastModificationString(Guid albumId)
		//{
		//    AssertAlbumOwner(albumId);

		//    DateTime date = BusinessLogics.AlbumManager.Instance.GetLastModificationDate(albumId);
		//    string result = Controls.StringUtility.Format(
		//        Resources.Strings.My_Album_LastModificationDate,
		//        date.ToShortDateString());
		//    return result;
		//}
	}
}
